package demo.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "USER")
public class User implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 788474806021519716L;

    @Id
    @GeneratedValue
    @Column(name = "USER_ID")
    private Long              id;

    @Column(name = "USER_LOGIN")
    private String            login;

    @Column(name = "USER_PWD")
    private String            password;

    @Column(name = "USER_1ST_NAME")
    private String            firstName;

    @Column(name = "USER_LAST_NAME")
    private String            lastName;

    @ManyToMany
    @JoinTable(name = "USER_ROLE", joinColumns = { @JoinColumn(name = "ASS_USER_ID", referencedColumnName = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ASS_ROLE_ID", referencedColumnName = "ROLE_ID") })
    private List<Role>        roles;

    public User() {
        super();
        roles = new ArrayList<>();
    }

    public Long getId() {
        return id;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(final String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(final String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(final String lastName) {
        this.lastName = lastName;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(final List<Role> roles) {
        this.roles = roles;
    }

    /**
     * @param role
     */
    public void addRole(final Role role) {
        if (role != null) {
            roles.add(role);
        }
    }

}
